#!/bin/sh
#
# This file is run by networkd-dispatcher, shall be installed to folder: /etc/networkd-dispatcher/routable.d/
# sudo sh -xvc 'f=99_enp0s8.sh; d=/etc/networkd-dispatcher/routable.d; [ -e "$d/$f" ] && exit 0; cp -a $f $d/ && f=$d/$f && chown 0:0 $f && chmod 0755 $f'
#
echo "$0" "$@"
[ "$IFACE" = "enp0s8" ] || exit 0
cf=/tmp/if-up-down-enp0s8.txt
# shellcheck disable=SC2154
if [ "$OperationalState" = "routable" ]; then
	echo Offlinemode=0 | tee $cf
elif [ "$OperationalState" = "no-carrier" ]; then
	echo Offlinemode=1 | tee $cf
else
	echo "Do nothing."
	exit 0
fi
echo "Restart apt-cacher-ng.service"
systemctl restart apt-cacher-ng.service
echo "End."

